package com.example.dangerouscargodriver.ui.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baiju.bjpopupwindow.Item.DLPopItem;
import com.baiju.bjpopupwindow.view.DLPopupWindow;
import com.baiju.netmanager.Http.IHttpRequest;
import com.baiju.style.citylist.Toast.ToastUtils;
import com.bumptech.glide.Glide;
import com.example.dangerouscargodriver.controller.AuthController;
import com.example.dangerouscargodriver.entry.HandleRecordInfo;
import com.example.dangerouscargodriver.entry.MyResourceDetailInfo;
import com.example.dangerouscargodriver.module.ResponseInfo;
import com.example.dangerouscargodriver.param.RemoteAPI;
import com.example.dangerouscargodriver.param.RemoteAPICmd;
import com.example.dangerouscargodriver.utils.DialogUtils;
import com.example.dangerouscargodriver.utils.TextUtils;
import com.example.dangerouscargodriver.widget.ActionBar;
import com.example.dangerouscargodriver.R;
import com.example.dangerouscargodriver.widget.ChooseItemDialog;
import com.example.dangerouscargodriver.widget.HandleRecordInfoView;
import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MyResourceDetailActivity extends HttpRequestActivity implements View.OnClickListener {

	private static final String TAG = "MyResourceDetailActivity";
	private ActionBar mActionBar = null;

	private DLPopupWindow mActionPopupWindow;
	private List<DLPopItem> mActionList = new ArrayList<>();
	private String mRecId = null;
	private MyResourceDetailInfo mResourceDetailInfo = null;

	private ImageView mOrderStatusIcon = null;
	private TextView mOrderStatusName = null;
	private TextView mOrderStatusTitle = null;
	private TextView mTotalPrice = null;
	private TextView mPayType = null;
	private TextView mRegTime = null;
	private TextView mStartCity = null;
	private TextView mEndCity = null;
	private TextView mSourceDistance = null;
	private TextView mSourceWeight = null;
	private TextView mSourceType = null;
	private TextView mContact = null;
	private TextView mLoadTime = null;
	private TextView mRemark = null;
	private LinearLayout mLayoutContent = null;
	private LinearLayout mHandleRecord = null;
	private TextView mOrderNo = null;
	private LinearLayout mLayoutPublishing = null;
	private LinearLayout mLayoutDiscussing = null;
	private LinearLayout mLayoutTransporting = null;
	private LinearLayout mLayoutTransportDone = null;
	private LinearLayout mOrderDone = null;
	private LinearLayout mLoseEfficacy = null;
	private LinearLayout mOrderCancel = null;

	private LinearLayout mPublishingOmitAction = null;
	private TextView mPublishingMatchLine = null;
	private TextView mPublishingEditResource = null;

	private LinearLayout mDiscussingOmitAction = null;
	private TextView mDiscussingCancelOrder = null;
	private TextView mDiscussingPayOrder = null;

	private LinearLayout mTransportingOmitAction = null;
	private TextView mTransportingCancelOrder = null;
	private TextView mTransportingConfirm = null;

	private LinearLayout mTransportDoneOmitAction = null;
	private TextView mTransportDoneConfirm = null;

	private LinearLayout mOrderDoneOmitAction = null;
	private TextView mOrderDoneDeleteOrder = null;
	private TextView mOrderDoneComment = null;
	private TextView mOrderDoneSeeComment = null;

	private LinearLayout mOrderLoseEfficacyOmitAction = null;
	private TextView mOrderLoseEfficacyDeleteOrder = null;

	private LinearLayout mOrderCancelingOmitAction = null;
	private TextView mOrderCancelingPullBack = null;

	private List<String> mReasonItem = new ArrayList<>();

	private TextView mTransportMark = null;
	private TextView mTransportGrade = null;
	private LinearLayout mLayoutStarNum = null;
	private TextView mTransporterInfo = null;
	private LinearLayout mLayoutTransportView = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.initHttpComponent(MyResourceDetailActivity.class);
		setContentView(R.layout.activity_my_resource_detail);
		mRecId = getIntent().getStringExtra("recid");

		mReasonItem.add("对方无法提供合适的车辆");
		mReasonItem.add("对方运价偏高");
		mReasonItem.add("对方电话打不通");
		mReasonItem.add("货物已通过其他方式运输");
		mReasonItem.add("双方协商后取消");
		mReasonItem.add("程序操作不方便");
		mReasonItem.add("其他理由");

		mOrderStatusIcon = findViewById(R.id.iv_order_status_icon);
		mOrderStatusName = findViewById(R.id.tv_order_status_name);
		mOrderStatusTitle = findViewById(R.id.tv_order_status_title);
		mTotalPrice = findViewById(R.id.tv_total_price);
		mPayType = findViewById(R.id.tv_pay_type);
		mRegTime = findViewById(R.id.tv_reg_time);
		mStartCity = findViewById(R.id.item_start_city);
		mEndCity = findViewById(R.id.item_end_city);
		mSourceDistance = findViewById(R.id.tv_source_distance);
		mSourceWeight = findViewById(R.id.tv_source_weight);
		mSourceType = findViewById(R.id.tv_source_type);
		mContact = findViewById(R.id.tv_contact);
		mLoadTime = findViewById(R.id.tv_load_time);
		mRemark = findViewById(R.id.tv_remark);
		mLayoutContent = findViewById(R.id.layout_content);
		mHandleRecord = findViewById(R.id.layout_handle_record);
		mOrderNo = findViewById(R.id.tv_order_no);
		mLayoutPublishing = findViewById(R.id.layout_publishing);
		mLayoutDiscussing = findViewById(R.id.layout_discussing);
		mLayoutTransporting = findViewById(R.id.layout_transporting);
		mLayoutTransportDone = findViewById(R.id.layout_transport_done);
		mOrderDone = findViewById(R.id.layout_order_done);
		mLoseEfficacy = findViewById(R.id.layout_order_lose_efficacy);
		mOrderCancel = findViewById(R.id.layout_order_canceling);

		mPublishingOmitAction = findViewById(R.id.iv_publishing_omit_action);
		mPublishingOmitAction.setOnClickListener(this);
		mPublishingMatchLine = findViewById(R.id.btn_publishing_match_line);
		mPublishingMatchLine.setOnClickListener(this);
		mPublishingEditResource = findViewById(R.id.btn_publishing_edit_resource);
		mPublishingEditResource.setOnClickListener(this);

		mDiscussingOmitAction = findViewById(R.id.iv_discussing_omit_action);
		mDiscussingOmitAction.setOnClickListener(this);
		mDiscussingCancelOrder = findViewById(R.id.btn_discussing_cancel_order);
		mDiscussingCancelOrder.setOnClickListener(this);
		mDiscussingPayOrder = findViewById(R.id.btn_discussing_order_pay);
		mDiscussingPayOrder.setOnClickListener(this);

		mTransportingOmitAction = findViewById(R.id.iv_transporting_omit_action);
		mTransportingOmitAction.setOnClickListener(this);
		mTransportingCancelOrder = findViewById(R.id.btn_transporting_cancel_order);
		mTransportingCancelOrder.setOnClickListener(this);
		mTransportingConfirm = findViewById(R.id.btn_transporting_confirm);
		mTransportingConfirm.setOnClickListener(this);

		mTransportDoneOmitAction = findViewById(R.id.iv_transport_done_omit_action);
		mTransportDoneOmitAction.setOnClickListener(this);
		mTransportDoneConfirm = findViewById(R.id.btn_transport_done_confirm);
		mTransportDoneConfirm.setOnClickListener(this);

		mOrderDoneOmitAction = findViewById(R.id.iv_order_done_omit_action);
		mOrderDoneOmitAction.setOnClickListener(this);
		mOrderDoneDeleteOrder = findViewById(R.id.btn_order_done_delete);
		mOrderDoneDeleteOrder.setOnClickListener(this);
		mOrderDoneComment = findViewById(R.id.btn_order_done_comment);
		mOrderDoneComment.setOnClickListener(this);
		mOrderDoneSeeComment = findViewById(R.id.btn_order_done_see_comment);
		mOrderDoneSeeComment.setOnClickListener(this);

		mOrderLoseEfficacyOmitAction = findViewById(R.id.iv_order_lose_efficacy_omit_action);
		mOrderLoseEfficacyOmitAction.setOnClickListener(this);
		mOrderLoseEfficacyDeleteOrder = findViewById(R.id.btn_order_lose_efficacy_delete);
		mOrderLoseEfficacyDeleteOrder.setOnClickListener(this);

		mOrderCancelingOmitAction = findViewById(R.id.iv_order_canceling_omit_action);
		mOrderCancelingOmitAction.setOnClickListener(this);
		mOrderCancelingPullBack = findViewById(R.id.btn_order_canceling_pull_back);
		mOrderCancelingPullBack.setOnClickListener(this);

		mTransportMark = findViewById(R.id.tv_transport_mark);
		mTransportGrade = findViewById(R.id.tv_transport_grade);
		mLayoutStarNum = findViewById(R.id.layout_star_num);
		mTransporterInfo = findViewById(R.id.tv_transporter_info);
		mLayoutTransportView = findViewById(R.id.layout_transport_view);

		initActionPopupWindow();
		mActionBar = findViewById(R.id.actionBarMyResourceDetail);
		mActionBar.setOnBackClickListener( new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	public void onResume(){
		super.onResume();
		executeGetResourceDetailInfo();
	}

	private void initActionPopupWindow() {
		DLPopItem item = new DLPopItem(0, "删除订单", 0x000000);
		mActionList.add(item);

		mActionPopupWindow = new DLPopupWindow(this, mActionList, DLPopupWindow.STYLE_DEF);

		mActionPopupWindow.setOnItemClickListener(new DLPopupWindow.OnItemClickListener() {
			@Override
			public void OnClick(int position) {
				if(position == 0){
				}
				else if(position == 1){

				}else{

				}
			}
		});
	}

	@SuppressLint("LongLogTag")
	@Override
	public void onClick(View v) {
		if(v.getId() == R.id.btn_publishing_edit_resource){
			//跳转到编辑货源页面
			Intent intent = new Intent(this, MyResourceInfoEditActivity.class);
			intent.putExtra("info", mResourceDetailInfo);
			startActivity(intent);
		}
		else if(v.getId() == R.id.btn_publishing_match_line){
			//获取匹配的线路信息
		}
		else if(v.getId() == R.id.iv_publishing_omit_action){
			//分享线路信息，如何实现??
		}
		else if(v.getId() == R.id.iv_discussing_omit_action){
			//联系客服，如何实现？？？
		}
		else if(v.getId() == R.id.btn_discussing_cancel_order){
			//取消订单
			ChooseItemDialog dialog = new ChooseItemDialog(this,
					"确认取消",
					"",
					 mReasonItem,
					"确认",
					"取消"
					);
			TextUtils.getBuilder().click(getResources().getString(R.string.resource_owner_cancel_order), getResources().getColor(R.color.red), new TextUtils.OnClickListener() {
				@Override
				public void onClick(int position) {
					switch (position){
						case 0:
							Intent intent = new Intent(getBaseContext(), ShowHtmlActivity.class);
							intent.putExtra("type", "4");
							startActivity(intent);
							break;
						default:
							break;
					}
				}
			}, "《运输标准规则》").clickInto(dialog.getMsgView());
			dialog.getMsgView().setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
			dialog.addClickListener(new ChooseItemDialog.AlertDialogBtnClickListener() {
				@Override
				public void clickPositive(List<Integer> select) {
					String reason = "";
					for(int index = 0; index < select.size(); index++){
						reason += mReasonItem.get(index) + ",";
					}
					if(reason.length() > 0){
						reason = reason.substring(0, reason.length() - 1);
					}
					executeDiscussingCancelOrder(reason);
				}

				@Override
				public void clickNegative() {

				}
			});
			dialog.showAlertDialog(false);
		}
		else if(v.getId() == R.id.btn_discussing_order_pay){
			//支付订单
			Log.d(TAG, "executeOrderPayAction");
			executeOrderPayAction();
		}
		else if(v.getId() == R.id.iv_transporting_omit_action){

		}
		else if(v.getId() == R.id.btn_transporting_cancel_order){
			//取消订单
			ChooseItemDialog dialog = new ChooseItemDialog(this,
					"确认取消",
					"",
					mReasonItem,
					"确认",
					"取消"
			);
			TextUtils.getBuilder().click(getResources().getString(R.string.resource_owner_cancel_order), getResources().getColor(R.color.red), new TextUtils.OnClickListener() {
				@Override
				public void onClick(int position) {
					switch (position){
						case 0:
							Intent intent = new Intent(getBaseContext(), ShowHtmlActivity.class);
							intent.putExtra("type", "4");
							startActivity(intent);
							break;
						default:
							break;
					}
				}
			}, "《运输标准规则》").clickInto(dialog.getMsgView());
			dialog.getMsgView().setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
			dialog.addClickListener(new ChooseItemDialog.AlertDialogBtnClickListener() {
				@Override
				public void clickPositive(List<Integer> select) {
					String reason = "";
					for(int index = 0; index < select.size(); index++){
						reason += mReasonItem.get(index) + ",";
					}
					if(reason.length() > 0){
						reason = reason.substring(0, reason.length() - 1);
					}
					executeTransportingCancelOrder();
				}

				@Override
				public void clickNegative() {

				}
			});
			dialog.showAlertDialog(false);
		}
		else if(v.getId() == R.id.btn_transporting_confirm){
			//确认送达
			DialogUtils.showAlertDialog(this,
					"确认完成",
					"请确认货物已经送达",
					"确定",
					"取消",
					false,
					new DialogUtils.AlertDialogBtnClickListener() {
						@Override
						public void clickPositive() {
							//negative
							executeTransportConfirm();
						}
						@Override
						public void clickNegative() {
							//positive
						}
					});
		}
		else if(v.getId() == R.id.iv_transport_done_omit_action){

		}
		else if(v.getId() == R.id.btn_transport_done_confirm){
			//确认送达
			DialogUtils.showAlertDialog(this,
					"确认完成",
					"请确认货物已经送达",
					"确定",
					"取消",
					false,
					new DialogUtils.AlertDialogBtnClickListener() {
						@Override
						public void clickPositive() {
							//negative
							executeTransportConfirm();
						}
						@Override
						public void clickNegative() {
							//positive
						}
					});
		}
		else if(v.getId() == R.id.iv_order_done_omit_action){

		}
		else if(v.getId() == R.id.btn_order_done_delete){
			//删除订单
			//与已失效的采用同一个接口
			DialogUtils.showAlertDialog(this,
					"确认删除",
					"确认要删除该订单吗？",
					"确定",
					"取消",
					false,
					new DialogUtils.AlertDialogBtnClickListener() {
						@Override
						public void clickPositive() {
							//negative
							executeLoseEfficacyDeleteResource();
						}
						@Override
						public void clickNegative() {
							//positive
						}
					});
		}
		else if(v.getId() == R.id.btn_order_done_comment){
			//进行评价
			Intent intent = new Intent(this, EvaluateOrderActivity.class);
			intent.putExtra("id", mResourceDetailInfo.getId());
			intent.putExtra("type", 2);
			startActivity(intent);
		}
		else if(v.getId() == R.id.btn_order_done_see_comment){
			//查看评价
			Intent intent = new Intent(this, EvaluateOrderDetailInfoActivity.class);
			intent.putExtra("id", mResourceDetailInfo.getId());
			startActivity(intent);
		}
		else if(v.getId() == R.id.iv_order_lose_efficacy_omit_action){

		}
		else if(v.getId() == R.id.btn_order_lose_efficacy_delete){
			//删除订单
			DialogUtils.showAlertDialog(this,
					"确认删除",
					"确认要删除该货源吗？",
					"确定",
					"取消",
					false,
					new DialogUtils.AlertDialogBtnClickListener() {
						@Override
						public void clickPositive() {
							//negative
							executeLoseEfficacyDeleteResource();
						}
						@Override
						public void clickNegative() {
							//positive
						}
					});
		}
		else if(v.getId() == R.id.iv_order_canceling_omit_action){

		}
		else if(v.getId() == R.id.btn_order_canceling_pull_back){
			//撤回取消
			executeCancelOrderPullBack();
		}
		else{

		}
	}

	private void executeDiscussingCancelOrder(String reason){
		if(mResourceDetailInfo != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			JSONObject param = new JSONObject();
			try {
				param.put("id", mResourceDetailInfo.getId());
				param.put("type", 1);
				param.put("handling_reason", reason);
			} catch (JSONException e) {
				e.printStackTrace();
			}

			sendHttpJsonRequest(
					IHttpRequest.RequestMethod.PUT_METHOD,
					RemoteAPI.REQUEST_V2_USER_SG_ORDER + "/" + mResourceDetailInfo.getId(),
					header,
					param,
					RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_DISCUSSING_CANCEL);
		}
		else{

		}
	}

	private void executeTransportingCancelOrder(){
		if(mResourceDetailInfo != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			JSONObject param = new JSONObject();
			try {
				param.put("id", mResourceDetailInfo.getId());
				param.put("type", 1);
				param.put("handling_reason", "其他理由");
			} catch (JSONException e) {
				e.printStackTrace();
			}

			sendHttpJsonRequest(
					IHttpRequest.RequestMethod.PUT_METHOD,
					RemoteAPI.REQUEST_V2_USER_SG_ORDER + "/" + mResourceDetailInfo.getId(),
					header,
					param,
					RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_TRANSPORTING_CANCEL);
		}
		else{

		}
	}

	private void executeCancelOrderPullBack(){
		if(mResourceDetailInfo != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			JSONObject param = new JSONObject();
			try {
				param.put("id", mResourceDetailInfo.getId());
				param.put("type", 4);
			} catch (JSONException e) {
				e.printStackTrace();
			}

			sendHttpJsonRequest(
					IHttpRequest.RequestMethod.PUT_METHOD,
					RemoteAPI.REQUEST_V2_USER_SG_ORDER + "/" + mResourceDetailInfo.getId(),
					header,
					param,
					RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_CANCELING_PULL_BACK);
		}
		else{

		}
	}

	private void executeTransportConfirm(){
		if(mResourceDetailInfo != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			JSONObject param = new JSONObject();
			try {
				param.put("id", mResourceDetailInfo.getId());
				param.put("type", 3);
			} catch (JSONException e) {
				e.printStackTrace();
			}

			sendHttpJsonRequest(
					IHttpRequest.RequestMethod.PUT_METHOD,
					RemoteAPI.REQUEST_V2_USER_SG_ORDER + "/" + mResourceDetailInfo.getId(),
					header,
					param,
					RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_TRANSPORT_DONE_CONFIRM);
		}
		else{

		}
	}

	private void executeOrderPayAction(){
		HashMap<String, String> header = new HashMap<String, String>();
		header.put("token", AuthController.Instance().getToken());

		JSONObject param = new JSONObject();
		try {
			param.put("type", 1);
			param.put("relevant_sign", Integer.parseInt(mResourceDetailInfo.getId()));
			param.put("pay_fee", mResourceDetailInfo.getTotal_final());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		sendHttpJsonRequest(
				RemoteAPI.REQUEST_V1_MAKE_PRE_ORDER,
				header,
				param,
				RemoteAPICmd.REQUEST_V1_MAKE_PRE_ORDER);
	}

	private void executeGetResourceDetailInfo(){
		if(mRecId != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			sendHttpRequest(
					IHttpRequest.RequestMethod.GET_METHOD,
					RemoteAPI.REQUEST_V2_USER_SG_SOURCE + "/" + mRecId,
					header,
					null,
					RemoteAPICmd.REQUEST_V2_USER_SG_SOURCE);
		}
	}

	private void refreshResourceDetailInfoView(){
		if(mResourceDetailInfo != null) {
			Glide.with(this).load(mResourceDetailInfo.getStatus_icon()).into(mOrderStatusIcon);
			mOrderStatusName.setText(mResourceDetailInfo.getStatus_name());
			mOrderStatusTitle.setText(mResourceDetailInfo.getStatus_desc());
			mTotalPrice.setText(mResourceDetailInfo.getExpected_price());
			if(mResourceDetailInfo.getPay_type().equals("2")){
				mPayType.setText(R.string.tv_pay_online);
			}
			else{
				mPayType.setText(R.string.tv_pay_offline);
			}
			mRegTime.setText(mResourceDetailInfo.getRegtime());
			mStartCity.setText(mResourceDetailInfo.getFrom_name());
			mEndCity.setText(mResourceDetailInfo.getTo_name());
			mSourceDistance.setText(mResourceDetailInfo.getSource_distance());
			mSourceWeight.setText(mResourceDetailInfo.getWeight() + "吨");
			mSourceType.setText(mResourceDetailInfo.getClassname());
			mContact.setText(mResourceDetailInfo.getContact());
			if(mResourceDetailInfo.getLoadtime2() != null){
				mLoadTime.setText(mResourceDetailInfo.getLoadtime() + "~" +
						mResourceDetailInfo.getLoadtime2());
			}
			else {
				mLoadTime.setText(mResourceDetailInfo.getLoadtime());
			}
			mRemark.setText(mResourceDetailInfo.getRemark());

			if(mResourceDetailInfo.getName() != null && !mResourceDetailInfo.getName().equals("")){
				View layout = LayoutInflater.from(this).inflate(R.layout.layout_resource_meta_info_item, null);
				TextView textView = layout.findViewById(R.id.tv_item_meta_string);
				textView.setText(mResourceDetailInfo.getName());
				mLayoutContent.addView(layout);
			}
			if(mResourceDetailInfo.getTruck_type() != null && !mResourceDetailInfo.getTruck_type().equals("")){
				String truckType = mResourceDetailInfo.getTruck_type();
				String[] truckTypeArray = truckType.split(",");

				for(int index = 0; index < truckTypeArray.length; index++){
					View layout = LayoutInflater.from(this).inflate(R.layout.layout_resource_meta_info_item, null);
					TextView textView = layout.findViewById(R.id.tv_item_meta_string);
					textView.setText(truckTypeArray[index]);
					mLayoutContent.addView(layout);
				}
			}

			mOrderNo.setText(mResourceDetailInfo.getSource_no());

			List<HandleRecordInfo> record = mResourceDetailInfo.getHandle_record();
			if(record != null && record.size() > 0){
				mHandleRecord.removeAllViews();
				for(int index = 0; index < record.size(); index++){
					HandleRecordInfoView view = new HandleRecordInfoView(this, record.get(index));
					mHandleRecord.addView(view);
				}
			}

			if(mResourceDetailInfo.getStatus().equals("1")){
				mLayoutPublishing.setVisibility(View.VISIBLE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
				mOrderCancel.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			else if(mResourceDetailInfo.getStatus().equals("2")){
				mLayoutDiscussing.setVisibility(View.VISIBLE);
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
				mOrderCancel.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			else if(mResourceDetailInfo.getStatus().equals("5") &&
				mResourceDetailInfo.getOrderstatus().equals("1")){
				mLayoutTransporting.setVisibility(View.VISIBLE);
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
				mOrderCancel.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			else if(mResourceDetailInfo.getStatus().equals("5") &&
					mResourceDetailInfo.getOrderstatus().equals("8")){
				mLayoutTransportDone.setVisibility(View.VISIBLE);
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
				mOrderCancel.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			//货主取消
			else if(mResourceDetailInfo.getStatus().equals("5") &&
					mResourceDetailInfo.getOrderstatus().equals("9")){
				mOrderCancel.setVisibility(View.VISIBLE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			else if(mResourceDetailInfo.getStatus().equals("6")){
				mOrderDone.setVisibility(View.VISIBLE);
				if(mResourceDetailInfo.getMark() == null){
					mOrderDoneComment.setVisibility(View.VISIBLE);
					mOrderDoneSeeComment.setVisibility(View.GONE);
				}
				else{
					mOrderDoneComment.setVisibility(View.GONE);
					mOrderDoneSeeComment.setVisibility(View.VISIBLE);
				}
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mLoseEfficacy.setVisibility(View.GONE);
			}
			else{
				mLoseEfficacy.setVisibility(View.VISIBLE);
				mLayoutPublishing.setVisibility(View.GONE);
				mLayoutDiscussing.setVisibility(View.GONE);
				mLayoutTransporting.setVisibility(View.GONE);
				mLayoutTransportDone.setVisibility(View.GONE);
				mOrderDone.setVisibility(View.GONE);
			}

			MyResourceDetailInfo.CompanyData companyData = mResourceDetailInfo.getCompany_data();
			if(mResourceDetailInfo.getCompany_data() != null){
				mLayoutTransportView.setVisibility(View.VISIBLE);
				mTransporterInfo.setText(companyData.getTitle_name());
				mTransportGrade.setText(companyData.getGrade() + "分");

				int grade = (int) Float.parseFloat(companyData.getGrade());
				mLayoutStarNum.removeAllViews();
				for(int index = 0; index < grade; index++){
					View layout = LayoutInflater.from(this).inflate(R.layout.layout_grade_star_item, null);
					mLayoutStarNum.addView(layout);
				}

			}
			else{
				mLayoutTransportView.setVisibility(View.GONE);
			}
		}
	}

	private void executeLoseEfficacyDeleteResource(){
		if(mResourceDetailInfo != null) {
			HashMap<String, String> header = new HashMap<String, String>();
			header.put("token", AuthController.Instance().getToken());

			JSONObject param = new JSONObject();
			try {
				param.put("id", mResourceDetailInfo.getId());
				param.put("type", 1);
				param.put("handling_reason", "其他理由");
			} catch (JSONException e) {
				e.printStackTrace();
			}

			sendHttpRequest(
					IHttpRequest.RequestMethod.DELETE_METHOD,
					RemoteAPI.REQUEST_V1_USER_SG_SOURCE + "/" + mRecId,
					header,
					null,
					RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_LOSE_EFFICACY_DELETE);
		}
		else{

		}
	}

	@SuppressLint("LongLogTag")
	@Override
	protected void onHttpResponse(int actionId, String response) {
		try {
			JSONObject res = new JSONObject(response);
			Gson gson = new Gson();
			if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_SOURCE){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					mResourceDetailInfo = gson.fromJson(res.getString("data"), MyResourceDetailInfo.class);
					refreshResourceDetailInfoView();
				}
			}
			//取消订单结果
			else if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_DISCUSSING_CANCEL){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "取消订单成功");
					executeGetResourceDetailInfo();
				}
				else{
					ToastUtils.showLongToast(this, res.getString("message"));
				}
			}
			//支付订单结果
			else if(actionId == RemoteAPICmd.REQUEST_V1_MAKE_PRE_ORDER){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "支付订单成功");
					executeGetResourceDetailInfo();
				}
				else{
					ToastUtils.showLongToast(this, res.getString("message"));
				}
			}
			else if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_TRANSPORTING_CANCEL){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "取消订单成功");
					executeGetResourceDetailInfo();
				}
				else{
					ToastUtils.showLongToast(this, res.getString("message"));
				}
			}
			else if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_TRANSPORT_DONE_CONFIRM){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "确认成功");
					//executeGetResourceDetailInfo();
					Intent intent = new Intent(this, EvaluateOrderActivity.class);
					intent.putExtra("id", mResourceDetailInfo.getId());
					intent.putExtra("type", 1);
					startActivity(intent);
				}
				else{
					ToastUtils.showLongToast(this, res.getString("message"));
				}
			}
			else if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_CANCELING_PULL_BACK){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "撤回取消订单成功");
					executeGetResourceDetailInfo();
				}
				else{
					ToastUtils.showLongToast(this, res.getString("message"));
				}
			}
			else if(actionId == RemoteAPICmd.REQUEST_V2_USER_SG_ORDER_LOSE_EFFICACY_DELETE){
				Log.d(TAG, "onResponse: " + response);
				ResponseInfo responseInfo = gson.fromJson(response, ResponseInfo.class);
				if(responseInfo != null && responseInfo.getStatus() == 1){
					ToastUtils.showLongToast(this, "删除成功");
					finish();
				}
				else{
					ToastUtils.showLongToast(this, "删除失败");
				}
			}
			else{

			}
		}
		catch (JSONException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void onHttpErrorResponse(int actionId, String response) {

	}
}